package com.orange.controller;

import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.orange.handler.AuthSchoolService;
import com.orange.handler.AuthTeachResourceService;
import com.orange.modules.bean.SessionUser;
import com.orange.modules.entity.school.AuthSchool;
import com.orange.modules.entity.school_data.AuthTeachResource;
import com.orange.util.ReturnCode;

@Controller
@RequestMapping("/teachResource")
public class AuthTeachResourceController extends BaseController{

	private static final Logger log = Logger.getLogger(AuthTeachResourceController.class);
	
	@Autowired
	private AuthTeachResourceService authTeachResourceService;
	
	@Autowired
	private AuthSchoolService authSchoolService;
	
	/**
	 * 新增教学资源
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/insertTeachResource" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> insertTeachResource(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			String latestProfessionalConstructionTime = map.get("latestProfessionalConstructionTime");
			String professionalTrainingProgram = map.get("professionalTrainingProgram");
			String requiredCoursesNum = map.get("requiredCoursesNum");
			String electiveCoursesNum = map.get("electiveCoursesNum");
			String onlineCourseTime = map.get("onlineCourseTime");
			String onlineAssessmentTime = map.get("onlineAssessmentTime");
			String teachingCycle = map.get("teachingCycle");
			String teachingSatisfaction = map.get("teachingSatisfaction");
			String creditSystemTime = map.get("creditSystemTime");
			String basicCourseCredit = map.get("basicCourseCredit");
			String professionalCourseCredits = map.get("professionalCourseCredits");
			String curriculumCredits = map.get("curriculumCredits");
			String countyNum = map.get("countyNum");
			String practiceBase  =map.get("practiceBase");
			String educationPracticeBase = map.get("educationPracticeBase");
			String teachingPracticeTime = map.get("teachingPracticeTime");
			String educationalProbation = map.get("educationalProbation");
			String educationalPractice = map.get("educationalPractice");
			String educationalPracticeTime = map.get("educationalPracticeTime");
			String baseInstructor  = map.get("baseInstructor");
			String ratioTeacherStudent = map.get("ratioTeacherStudent");
			String fulltimeTeachersLatest = map.get("fulltimeTeachersLatest");
			String parttimeTeachersLatest = map.get("parttimeTeachersLatest");
			String sid = map.get("sid");
			String loginType = map.get("loginType");
			String status = map.get("status");
			if(latestProfessionalConstructionTime == null || StringUtils.isBlank(latestProfessionalConstructionTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"最新专业建设规划起止年限不能为空");
			if(professionalTrainingProgram == null || StringUtils.isBlank(professionalTrainingProgram))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"最新专业培养方案启用时间不能为空");
			if(requiredCoursesNum == null || StringUtils.isBlank(requiredCoursesNum))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"本专业必修课门数（门)不能为空");
			if(electiveCoursesNum == null || StringUtils.isBlank(electiveCoursesNum))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"本专业选修课门数（门）不能为空");
			if(onlineCourseTime == null || StringUtils.isBlank(onlineCourseTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"网上选课系统启用时间不能为空");
			if(onlineAssessmentTime == null || StringUtils.isBlank(onlineAssessmentTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"网上评教系统启用时间不能为空");
			if(teachingCycle == null || StringUtils.isBlank(teachingCycle))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学生评教周期（月/学期/年/学年)不能为空");
			if(teachingSatisfaction == null || StringUtils.isBlank(teachingSatisfaction))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学生评教满意率最近数据（%）不能为空");
			if(creditSystemTime == null || StringUtils.isBlank(creditSystemTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学分制认定办法实施起始时间不能为空");
			if(basicCourseCredit == null || StringUtils.isBlank(basicCourseCredit))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"公共基础课程学分占比（%）不能为空");
			if(professionalCourseCredits == null || StringUtils.isBlank(professionalCourseCredits))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学科专业课程学分占比（%）不能为空");
			if(curriculumCredits == null || StringUtils.isBlank(curriculumCredits))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教师教育课程学分占比（%）不能为空");
			if(countyNum == null || StringUtils.isBlank(countyNum))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"本专业教育实践合作县市区数量（个）不能为空");
			if(practiceBase == null || StringUtils.isBlank(practiceBase))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育实习基地(校/园)数量（个）不能为空");
			if(educationPracticeBase == null || StringUtils.isBlank(educationPracticeBase))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育实习基地平均接待实习生数（人）不能为空");
			if(teachingPracticeTime == null || StringUtils.isBlank(teachingPracticeTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"保教实践时间总量（周）不能为空");
			if(educationalProbation == null || StringUtils.isBlank(educationalProbation))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育见习（课时）不能为空");
			if(educationalPractice == null || StringUtils.isBlank(educationalPractice))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育实习（周）不能为空");
			if(educationalPracticeTime == null || StringUtils.isBlank(educationalPracticeTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育实习安排一般在第几学期不能为空");
			if(baseInstructor == null || StringUtils.isBlank(baseInstructor))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"基地指导教师与实习生之比（%）不能为空");
			if(ratioTeacherStudent == null || StringUtils.isBlank(ratioTeacherStudent))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"高校指导教师与实习生之比（%）不能为空");
			if(fulltimeTeachersLatest == null || StringUtils.isBlank(fulltimeTeachersLatest))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学生对专任教师满意率最新数据（%）不能为空");
			if(parttimeTeachersLatest == null || StringUtils.isBlank(parttimeTeachersLatest))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学生对兼职教师满意率最新数据（%）不能为空");
			if(sid == null || StringUtils.isBlank(sid))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学校ID不能为空");
			if(loginType == null || StringUtils.isBlank(loginType))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"专业类型不能为空");
			if(status == null || StringUtils.isBlank(status))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"数据状态不能为空");
						AuthTeachResource atr = new AuthTeachResource();
			atr.setBaseInstructor(baseInstructor);
			atr.setBasicCourseCredit(basicCourseCredit);
			atr.setCountyNum(countyNum);
			atr.setCreatetime(sdf.format(new Date()));
			atr.setCreditSystemTime(creditSystemTime);
			atr.setCurriculumCredits(curriculumCredits);
			atr.setEducationalPractice(educationalPractice);
			atr.setEducationalPracticeTime(educationalPracticeTime);
			atr.setEducationPracticeBase(educationPracticeBase);
			atr.setEducationalProbation(educationalProbation);
			atr.setElectiveCoursesNum(electiveCoursesNum);
			atr.setFulltimeTeachersLatest(fulltimeTeachersLatest);
			atr.setLatestProfessionalConstructionTime(latestProfessionalConstructionTime);
			atr.setLoginType(loginType);
			atr.setOnlineAssessmentTime(onlineAssessmentTime);
			atr.setOnlineCourseTime(onlineCourseTime);
			atr.setParttimeTeachersLatest(parttimeTeachersLatest);
			atr.setPracticeBase(practiceBase);
			atr.setProfessionalCourseCredits(professionalCourseCredits);
			atr.setProfessionalTrainingProgram(professionalTrainingProgram);
			atr.setRatioTeacherStudent(ratioTeacherStudent);
			atr.setRequiredCoursesNum(requiredCoursesNum);
			atr.setSid(sid);
			atr.setStatus(status);
			atr.setTeachingCycle(teachingCycle);
			atr.setTeachingPracticeTime(teachingPracticeTime);
			atr.setTeachingSatisfaction(teachingSatisfaction);
			authTeachResourceService.insertTeachResource(atr);
			return toResponse(atr,ReturnCode.SUCCESS,"新增成功");
		} catch (Exception e) {
			log.error(e);
			return toResponse(null,ReturnCode.FAIL,"新增失败");
		}
		
	}
	
	/**
	 * 根据当前用户查询教学资源信息
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryTeacherResourceDataBySchoolId" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> queryTeacherResourceDataBySchoolId(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		String schoolId = map.get("schoolId");
		String loginType = map.get("loginType");
		if(schoolId==null || StringUtils.isBlank(schoolId))
			return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学校ID不能为空");
		if(loginType==null || StringUtils.isBlank(loginType))
			return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"专业类型不能为空");
		AuthTeachResource atr = authTeachResourceService.queryAuthTeachResourceDataBySchoolId(schoolId, loginType);
		return toResponse(atr,ReturnCode.SUCCESS,"查询成功");
	}
	
	/**
	 * 修改教学资源表
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/updateTeachResourceData" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> updateTeachResourceData(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		String schoolId = map.get("sid");
		String loginType = map.get("loginType");
		if(schoolId==null || StringUtils.isBlank(schoolId))
			return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学校ID不能为空");
		if(loginType==null || StringUtils.isBlank(loginType))
			return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"专业类型不能为空");
		try {
			AuthTeachResource atr = authTeachResourceService.queryAuthTeachResourceDataBySchoolId(schoolId, loginType);
			if(atr!=null){
				String latestProfessionalConstructionTime = map.get("latestProfessionalConstructionTime");
				String professionalTrainingProgram = map.get("professionalTrainingProgram");
				String requiredCoursesNum = map.get("requiredCoursesNum");
				String electiveCoursesNum = map.get("electiveCoursesNum");
				String onlineCourseTime = map.get("onlineCourseTime");
				String onlineAssessmentTime = map.get("onlineAssessmentTime");
				String teachingCycle = map.get("teachingCycle");
				String teachingSatisfaction = map.get("teachingSatisfaction");
				String creditSystemTime = map.get("creditSystemTime");
				String basicCourseCredit = map.get("basicCourseCredit");
				String professionalCourseCredits = map.get("professionalCourseCredits");
				String curriculumCredits = map.get("curriculumCredits");
				String countyNum = map.get("countyNum");
				String practiceBase  =map.get("practiceBase");
				String educationPracticeBase = map.get("educationPracticeBase");
				String teachingPracticeTime = map.get("teachingPracticeTime");
				String educationalProbation = map.get("educationalProbation");
				String educationalPractice = map.get("educationalPractice");
				String educationalPracticeTime = map.get("educationalPracticeTime");
				String baseInstructor  = map.get("baseInstructor");
				String ratioTeacherStudent = map.get("ratioTeacherStudent");
				String fulltimeTeachersLatest = map.get("fulltimeTeachersLatest");
				String parttimeTeachersLatest = map.get("parttimeTeachersLatest");
				String status = map.get("status");
				if(latestProfessionalConstructionTime!=null && StringUtils.isNotBlank(latestProfessionalConstructionTime))
					atr.setLatestProfessionalConstructionTime(latestProfessionalConstructionTime);
				if(professionalTrainingProgram!=null && StringUtils.isNotBlank(professionalTrainingProgram))
					atr.setProfessionalTrainingProgram(professionalTrainingProgram);
				if(requiredCoursesNum!=null && StringUtils.isNotBlank(requiredCoursesNum))
					atr.setRequiredCoursesNum(requiredCoursesNum);
				if(electiveCoursesNum!=null && StringUtils.isNotBlank(electiveCoursesNum))
					atr.setElectiveCoursesNum(electiveCoursesNum);
				if(onlineCourseTime!=null && StringUtils.isNotBlank(onlineCourseTime))
					atr.setOnlineCourseTime(onlineCourseTime);
				if(onlineAssessmentTime!=null && StringUtils.isNotBlank(onlineAssessmentTime))
					atr.setOnlineAssessmentTime(onlineAssessmentTime);
				if(teachingCycle!=null && StringUtils.isNotBlank(teachingCycle))
					atr.setTeachingCycle(teachingCycle);
				if(teachingSatisfaction!=null && StringUtils.isNotBlank(teachingSatisfaction))
					atr.setTeachingSatisfaction(teachingSatisfaction);
				if(creditSystemTime!=null && StringUtils.isNotBlank(creditSystemTime))
					atr.setCreditSystemTime(creditSystemTime);
				if(basicCourseCredit!=null && StringUtils.isNotBlank(basicCourseCredit))
					atr.setBasicCourseCredit(basicCourseCredit);
				if(professionalCourseCredits!=null && StringUtils.isNotBlank(professionalCourseCredits))
					atr.setProfessionalCourseCredits(professionalCourseCredits);
				if(curriculumCredits!=null && StringUtils.isNotBlank(curriculumCredits))
					atr.setCurriculumCredits(curriculumCredits);
				if(countyNum!=null && StringUtils.isNotBlank(countyNum))
					atr.setCountyNum(countyNum);
				if(practiceBase!=null && StringUtils.isNotBlank(practiceBase))
					atr.setPracticeBase(practiceBase);
				if(educationPracticeBase!=null && StringUtils.isNotBlank(educationPracticeBase))
					atr.setEducationPracticeBase(educationPracticeBase);
				if(teachingPracticeTime!=null && StringUtils.isNotBlank(teachingPracticeTime))
					atr.setTeachingPracticeTime(teachingPracticeTime);
				if(educationalProbation!=null && StringUtils.isNotBlank(educationalProbation))
					atr.setEducationalProbation(educationalProbation);
				if(educationalPractice!=null && StringUtils.isNotBlank(educationalPractice))
					atr.setEducationalPractice(educationalPractice);
				if(educationalPracticeTime!=null && StringUtils.isNotBlank(educationalPracticeTime))
					atr.setEducationalPracticeTime(educationalPracticeTime);
				if(baseInstructor!=null && StringUtils.isNotBlank(baseInstructor))
					atr.setBaseInstructor(baseInstructor);
				if(ratioTeacherStudent!=null && StringUtils.isNotBlank(ratioTeacherStudent))
					atr.setRatioTeacherStudent(ratioTeacherStudent);
				if(fulltimeTeachersLatest!=null && StringUtils.isNotBlank(fulltimeTeachersLatest))
					atr.setFulltimeTeachersLatest(fulltimeTeachersLatest);
				if(parttimeTeachersLatest!=null && StringUtils.isNotBlank(parttimeTeachersLatest))
					atr.setParttimeTeachersLatest(parttimeTeachersLatest);
				if(status!=null && StringUtils.isNotBlank(status))
					atr.setStatus(status);
				authTeachResourceService.insertTeachResource(atr);
			}
			return toResponse(atr,ReturnCode.SUCCESS,"修改成功");
		} catch (Exception e) {
			log.error(e);
			return toResponse(null,ReturnCode.FAIL,"修改失败");
		}	
	}
	/**************************************************************************************************************/
	/**
	 * 新增教学资源
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/insertTeachResource1" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> insertTeachResource1(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			String sid = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
			if(null==sid){
				return toResponse(null,ReturnCode.NOLOGIN,"未登陆");
			}
			String subject = (String) request.getSession().getAttribute(SessionUser.SESSION_STATUS);//学科
			
			String latestProfessionalConstructionTime = map.get("latestProfessionalConstructionTime");
			String professionalTrainingProgram = map.get("professionalTrainingProgram");
			String requiredCoursesNum = map.get("requiredCoursesNum");
			String electiveCoursesNum = map.get("electiveCoursesNum");
			String onlineCourseTime = map.get("onlineCourseTime");
			String onlineAssessmentTime = map.get("onlineAssessmentTime");
			String teachingCycle = map.get("teachingCycle");
			String teachingSatisfaction = map.get("teachingSatisfaction");
			String creditSystemTime = map.get("creditSystemTime");
			String basicCourseCredit = map.get("basicCourseCredit");
			String professionalCourseCredits = map.get("professionalCourseCredits");
			String curriculumCredits = map.get("curriculumCredits");
			String countyNum = map.get("countyNum");
			String practiceBase  =map.get("practiceBase");
			String educationPracticeBase = map.get("educationPracticeBase");
			String teachingPracticeTime = map.get("teachingPracticeTime");
			String educationalProbation = map.get("educationalProbation");
			String educationalPractice = map.get("educationalPractice");
			String educationalPracticeTime = map.get("educationalPracticeTime");
			String baseInstructor  = map.get("baseInstructor");
			String ratioTeacherStudent = map.get("ratioTeacherStudent");
			String fulltimeTeachersLatest = map.get("fulltimeTeachersLatest");
			String parttimeTeachersLatest = map.get("parttimeTeachersLatest");
			String remark1=map.get("remark1");
			String remark2 = map.get("remark2");
			String remark3 = map.get("remark3");
			String remark4 = map.get("remark4");
			String remark5 = map.get("remark5");
			String remark6 = map.get("remark6");
			String remark7 = map.get("remark7");
			String remark8 = map.get("remark8");
			String remark9 = map.get("remark9");
			String remark10 = map.get("remark10");
			String remark11 = map.get("remark11");
			String remark12 = map.get("remark12");
			String remark13 = map.get("remark13");
			String remark14 = map.get("remark14");
			String remark15 = map.get("remark15");
			String remark16 = map.get("remark16");
			String remark17 = map.get("remark17");
			String remark18 = map.get("remark18");
			String remark19 = map.get("remark19");
			String remark20 = map.get("remark20");
			String remark21 = map.get("remark21");
			String remark22 = map.get("remark22");
			String remark23 = map.get("remark23");
			String status ="0";
			if(latestProfessionalConstructionTime == null || StringUtils.isBlank(latestProfessionalConstructionTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"最新专业建设规划起止年限不能为空");
			if(professionalTrainingProgram == null || StringUtils.isBlank(professionalTrainingProgram))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"最新专业培养方案启用时间不能为空");
			if(requiredCoursesNum == null || StringUtils.isBlank(requiredCoursesNum))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"本专业必修课门数（门)不能为空");
			if(electiveCoursesNum == null || StringUtils.isBlank(electiveCoursesNum))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"本专业选修课门数（门）不能为空");
			if(onlineCourseTime == null || StringUtils.isBlank(onlineCourseTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"网上选课系统启用时间不能为空");
			if(onlineAssessmentTime == null || StringUtils.isBlank(onlineAssessmentTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"网上评教系统启用时间不能为空");
			if(teachingCycle == null || StringUtils.isBlank(teachingCycle))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学生评教周期（月/学期/年/学年)不能为空");
			if(teachingSatisfaction == null || StringUtils.isBlank(teachingSatisfaction))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学生评教满意率最近数据（%）不能为空");
			if(creditSystemTime == null || StringUtils.isBlank(creditSystemTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学分制认定办法实施起始时间不能为空");
			if(basicCourseCredit == null || StringUtils.isBlank(basicCourseCredit))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"公共基础课程学分占比（%）不能为空");
			if(professionalCourseCredits == null || StringUtils.isBlank(professionalCourseCredits))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学科专业课程学分占比（%）不能为空");
			if(curriculumCredits == null || StringUtils.isBlank(curriculumCredits))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教师教育课程学分占比（%）不能为空");
			if(countyNum == null || StringUtils.isBlank(countyNum))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"本专业教育实践合作县市区数量（个）不能为空");
			if(practiceBase == null || StringUtils.isBlank(practiceBase))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育实习基地(校/园)数量（个）不能为空");
			if(educationPracticeBase == null || StringUtils.isBlank(educationPracticeBase))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育实习基地平均接待实习生数（人）不能为空");
			if(teachingPracticeTime == null || StringUtils.isBlank(teachingPracticeTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"保教实践时间总量（周）不能为空");
			if(educationalProbation == null || StringUtils.isBlank(educationalProbation))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育见习（课时）不能为空");
			if(educationalPractice == null || StringUtils.isBlank(educationalPractice))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育实习（周）不能为空");
			if(educationalPracticeTime == null || StringUtils.isBlank(educationalPracticeTime))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"教育实习安排一般在第几学期不能为空");
			if(baseInstructor == null || StringUtils.isBlank(baseInstructor))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"基地指导教师与实习生之比（%）不能为空");
			if(ratioTeacherStudent == null || StringUtils.isBlank(ratioTeacherStudent))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"高校指导教师与实习生之比（%）不能为空");
			if(fulltimeTeachersLatest == null || StringUtils.isBlank(fulltimeTeachersLatest))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学生对专任教师满意率最新数据（%）不能为空");
			if(parttimeTeachersLatest == null || StringUtils.isBlank(parttimeTeachersLatest))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学生对兼职教师满意率最新数据（%）不能为空");
			if(sid == null || StringUtils.isBlank(sid))
				return toResponse(null,ReturnCode.PARAMETER_NOT_NULL,"学校ID不能为空");
			String remark = remark1+"#"+remark2+"#"+remark3+"#"+remark4+"#"+remark5+"#"+remark6+"#"+remark7+"#"+remark8+"#"+remark9+"#"+remark10+"#"+remark11+"#"+remark12+"#"+remark13+"#"+remark14+"#"
					  + remark15+"#"+remark16+"#"+remark17+"#"+remark18+"#"+remark19+"#"+remark20+"#"+remark21+"#"+remark22+"#"+remark23;
			AuthTeachResource atr = new AuthTeachResource();
			atr.setBaseInstructor(baseInstructor);
			atr.setBasicCourseCredit(basicCourseCredit);
			atr.setCountyNum(countyNum);
			atr.setCreatetime(sdf.format(new Date()));
			atr.setCreditSystemTime(creditSystemTime);
			atr.setCurriculumCredits(curriculumCredits);
			atr.setEducationalPractice(educationalPractice);
			atr.setEducationalPracticeTime(educationalPracticeTime);
			atr.setEducationPracticeBase(educationPracticeBase);
			atr.setEducationalProbation(educationalProbation);
			atr.setElectiveCoursesNum(electiveCoursesNum);
			atr.setFulltimeTeachersLatest(fulltimeTeachersLatest);
			atr.setLatestProfessionalConstructionTime(latestProfessionalConstructionTime);
			atr.setLoginType(subject);
			atr.setOnlineAssessmentTime(onlineAssessmentTime);
			atr.setOnlineCourseTime(onlineCourseTime);
			atr.setParttimeTeachersLatest(parttimeTeachersLatest);
			atr.setPracticeBase(practiceBase);
			atr.setProfessionalCourseCredits(professionalCourseCredits);
			atr.setProfessionalTrainingProgram(professionalTrainingProgram);
			atr.setRatioTeacherStudent(ratioTeacherStudent);
			atr.setRequiredCoursesNum(requiredCoursesNum);
			atr.setSid(sid);
			atr.setStatus(status);
			atr.setTeachingCycle(teachingCycle);
			atr.setTeachingPracticeTime(teachingPracticeTime);
			atr.setTeachingSatisfaction(teachingSatisfaction);
			atr.setRemark(remark);
			authTeachResourceService.insertTeachResource(atr);
			AuthSchool as = authSchoolService.queryAuthSchoolInfoBypid(sid);
			
			atr.setLoginType(subject);
			
			if("1".equals(status)){
				if("1101".equals(subject) ){ //如果是理科
					if(as.getScience().equals("2"))  //如果是登陆过 
						as.setScience("4");
					if(as.getScience().equals("3"))   //如果填写过基础数据状态表
						as.setScience("5");
				}
				if("1102".equals(subject) ){ //如果是文科
					if(as.getLiberalarts().equals("2"))  //如果是登陆过 
						as.setLiberalarts("4");
					if(as.getLiberalarts().equals("3"))   //如果填写过基础数据状态表
						as.setLiberalarts("5");
				}
				if("1103".equals(subject) ){ //如果是整体申报
					if(as.getWholeDeclaration().equals("2"))  //如果是登陆过 
						as.setWholeDeclaration("4");
					if(as.getWholeDeclaration().equals("3"))   //如果填写过基础数据状态表
						as.setWholeDeclaration("5");
				}
			}
			authSchoolService.updateAuthSchoolInfo(as);
			return toResponse(atr,ReturnCode.SUCCESS,"新增成功");
		} catch (Exception e) {
			log.error(e);
			return toResponse(null,ReturnCode.FAIL,"新增失败");
		}
		
	}
	
	/**
	 * 根据当前用户查询教学资源信息
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryTeacherResourceDataBySchoolId1" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> queryTeacherResourceDataBySchoolId1(HttpServletRequest request) throws SQLException{
		String sid = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null==sid){
			return toResponse(null,ReturnCode.NOLOGIN,"未登陆");
		}
		String subject = (String) request.getSession().getAttribute(SessionUser.SESSION_STATUS);//学科
		
		AuthTeachResource atr = authTeachResourceService.queryAuthTeachResourceDataBySchoolId(sid, subject);
		return toResponse(atr,ReturnCode.SUCCESS,"查询成功");
	}
	
	/**
	 * 修改教学资源表
	 * @param request
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/updateTeachResourceData1" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.POST)
	@ResponseBody
	public ResponseEntity<String> updateTeachResourceData1(HttpServletRequest request,@RequestBody Map<String ,String> map) throws SQLException{
		String sid = (String) request.getSession().getAttribute(SessionUser.SESSION_USER_KEY);
		if(null==sid){
			return toResponse(null,ReturnCode.NOLOGIN,"未登陆");
		}
		String subject = (String) request.getSession().getAttribute(SessionUser.SESSION_STATUS);//学科
		
		try {
			AuthTeachResource atr = authTeachResourceService.queryAuthTeachResourceDataBySchoolId(sid, subject);
			if(atr!=null){
				String latestProfessionalConstructionTime = map.get("latestProfessionalConstructionTime");
				String professionalTrainingProgram = map.get("professionalTrainingProgram");
				String requiredCoursesNum = map.get("requiredCoursesNum");
				String electiveCoursesNum = map.get("electiveCoursesNum");
				String onlineCourseTime = map.get("onlineCourseTime");
				String onlineAssessmentTime = map.get("onlineAssessmentTime");
				String teachingCycle = map.get("teachingCycle");
				String teachingSatisfaction = map.get("teachingSatisfaction");
				String creditSystemTime = map.get("creditSystemTime");
				String basicCourseCredit = map.get("basicCourseCredit");
				String professionalCourseCredits = map.get("professionalCourseCredits");
				String curriculumCredits = map.get("curriculumCredits");
				String countyNum = map.get("countyNum");
				String practiceBase  =map.get("practiceBase");
				String educationPracticeBase = map.get("educationPracticeBase");
				String teachingPracticeTime = map.get("teachingPracticeTime");
				String educationalProbation = map.get("educationalProbation");
				String educationalPractice = map.get("educationalPractice");
				String educationalPracticeTime = map.get("educationalPracticeTime");
				String baseInstructor  = map.get("baseInstructor");
				String ratioTeacherStudent = map.get("ratioTeacherStudent");
				String fulltimeTeachersLatest = map.get("fulltimeTeachersLatest");
				String parttimeTeachersLatest = map.get("parttimeTeachersLatest");
				String remark1=map.get("remark1");
				String remark2 = map.get("remark2");
				String remark3 = map.get("remark3");
				String remark4 = map.get("remark4");
				String remark5 = map.get("remark5");
				String remark6 = map.get("remark6");
				String remark7 = map.get("remark7");
				String remark8 = map.get("remark8");
				String remark9 = map.get("remark9");
				String remark10 = map.get("remark10");
				String remark11 = map.get("remark11");
				String remark12 = map.get("remark12");
				String remark13 = map.get("remark13");
				String remark14 = map.get("remark14");
				String remark15 = map.get("remark15");
				String remark16 = map.get("remark16");
				String remark17 = map.get("remark17");
				String remark18 = map.get("remark18");
				String remark19 = map.get("remark19");
				String remark20 = map.get("remark20");
				String remark21 = map.get("remark21");
				String remark22 = map.get("remark22");
				String remark23 = map.get("remark23");
			
				if(latestProfessionalConstructionTime!=null && StringUtils.isNotBlank(latestProfessionalConstructionTime))
					atr.setLatestProfessionalConstructionTime(latestProfessionalConstructionTime);
				if(professionalTrainingProgram!=null && StringUtils.isNotBlank(professionalTrainingProgram))
					atr.setProfessionalTrainingProgram(professionalTrainingProgram);
				if(requiredCoursesNum!=null && StringUtils.isNotBlank(requiredCoursesNum))
					atr.setRequiredCoursesNum(requiredCoursesNum);
				if(electiveCoursesNum!=null && StringUtils.isNotBlank(electiveCoursesNum))
					atr.setElectiveCoursesNum(electiveCoursesNum);
				if(onlineCourseTime!=null && StringUtils.isNotBlank(onlineCourseTime))
					atr.setOnlineCourseTime(onlineCourseTime);
				if(onlineAssessmentTime!=null && StringUtils.isNotBlank(onlineAssessmentTime))
					atr.setOnlineAssessmentTime(onlineAssessmentTime);
				if(teachingCycle!=null && StringUtils.isNotBlank(teachingCycle))
					atr.setTeachingCycle(teachingCycle);
				if(teachingSatisfaction!=null && StringUtils.isNotBlank(teachingSatisfaction))
					atr.setTeachingSatisfaction(teachingSatisfaction);
				if(creditSystemTime!=null && StringUtils.isNotBlank(creditSystemTime))
					atr.setCreditSystemTime(creditSystemTime);
				if(basicCourseCredit!=null && StringUtils.isNotBlank(basicCourseCredit))
					atr.setBasicCourseCredit(basicCourseCredit);
				if(professionalCourseCredits!=null && StringUtils.isNotBlank(professionalCourseCredits))
					atr.setProfessionalCourseCredits(professionalCourseCredits);
				if(curriculumCredits!=null && StringUtils.isNotBlank(curriculumCredits))
					atr.setCurriculumCredits(curriculumCredits);
				if(countyNum!=null && StringUtils.isNotBlank(countyNum))
					atr.setCountyNum(countyNum);
				if(practiceBase!=null && StringUtils.isNotBlank(practiceBase))
					atr.setPracticeBase(practiceBase);
				if(educationPracticeBase!=null && StringUtils.isNotBlank(educationPracticeBase))
					atr.setEducationPracticeBase(educationPracticeBase);
				if(teachingPracticeTime!=null && StringUtils.isNotBlank(teachingPracticeTime))
					atr.setTeachingPracticeTime(teachingPracticeTime);
				if(educationalProbation!=null && StringUtils.isNotBlank(educationalProbation))
					atr.setEducationalProbation(educationalProbation);
				if(educationalPractice!=null && StringUtils.isNotBlank(educationalPractice))
					atr.setEducationalPractice(educationalPractice);
				if(educationalPracticeTime!=null && StringUtils.isNotBlank(educationalPracticeTime))
					atr.setEducationalPracticeTime(educationalPracticeTime);
				if(baseInstructor!=null && StringUtils.isNotBlank(baseInstructor))
					atr.setBaseInstructor(baseInstructor);
				if(ratioTeacherStudent!=null && StringUtils.isNotBlank(ratioTeacherStudent))
					atr.setRatioTeacherStudent(ratioTeacherStudent);
				if(fulltimeTeachersLatest!=null && StringUtils.isNotBlank(fulltimeTeachersLatest))
					atr.setFulltimeTeachersLatest(fulltimeTeachersLatest);
				if(parttimeTeachersLatest!=null && StringUtils.isNotBlank(parttimeTeachersLatest))
					atr.setParttimeTeachersLatest(parttimeTeachersLatest);
				String remark = remark1+"#"+remark2+"#"+remark3+"#"+remark4+"#"+remark5+"#"+remark6+"#"+remark7+"#"+remark8+"#"+remark9+"#"+remark10+"#"+remark11+"#"+remark12+"#"+remark13+"#"+remark14+"#"
						  + remark15+"#"+remark16+"#"+remark17+"#"+remark18+"#"+remark19+"#"+remark20+"#"+remark21+"#"+remark22+"#"+remark23;
				atr.setRemark(remark);
				atr.setStatus("1");
				authTeachResourceService.insertTeachResource(atr);
			}
			return toResponse(atr,ReturnCode.SUCCESS,"修改成功");
		} catch (Exception e) {
			log.error(e);
			return toResponse(null,ReturnCode.FAIL,"修改失败");
		}
	}
	
	/**
	 * pid==>sid
	 * @param request
	 * @return
	 * @throws SQLException
	 */
	@RequestMapping(value = "/queryTeacheResourceDataBySidPid" ,produces = MediaType.APPLICATION_JSON_VALUE+";charset=UTF-8", method=RequestMethod.GET)
	@ResponseBody
	public ResponseEntity<String> queryTeacheResourceDataBySidPid(HttpServletRequest request,@RequestParam String schoolid) throws SQLException{
		//String sid = "10058";	
		try {
			AuthTeachResource atr = authTeachResourceService.queryAuthTeachResourceDataBySchoolId(schoolid, null);
			return toResponse(atr,ReturnCode.SUCCESS,"查询教学数据成功");
		} catch (Exception e) {
			log.error("查询教学数据失败",e);
			return toResponse(null,ReturnCode.FAIL,"查询教学数据失败");
		}
	}
}
